//
//  UIView+IBInspectable.swift
//  SinaWeibo
//
//  Created by 李亮亮 on 16/4/6.
//  Copyright © 2016年 Big Fish. All rights reserved.
//

import UIKit

extension UIView {
    
    
    // 设置圆角
    @IBInspectable var cornerRadius: CGFloat {
        get {
            // 返回layer.cornerRadius
            return layer.cornerRadius
        }
        
        set {
            // 设置layer.cornerRadius
            layer.cornerRadius = newValue
            // 设置maskToBounds
            if newValue > 0 {
                layer.masksToBounds = true
            } else {
                layer.masksToBounds = false
            }
        }
    }
    
    // 设置宽度
    @IBInspectable var borderWidth: CGFloat {
        get {
            return layer.borderWidth
        }
        
        set {
            layer.borderWidth = newValue
        }
    }
    
    // 颜色
    @IBInspectable var borderColor: UIColor? {
        get {
            if let color = layer.borderColor {
                return UIColor(CGColor: color)
            }
            return nil
        }
        set {
            layer.borderColor = newValue?.CGColor
        }
    }
}



